﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Airport
{
    [Serializable]
    [DataContract]
    [KnownType(typeof(Node))]
    [KnownType(typeof(RunwayStatus))]
    public class Runway : Surface
    {

        private int _heading;
        private RunwayStatus _currentRunwayStatus;
        private String _direction1;
        private String _direction2;
        private Node _labelLocation;

        /// <summary>
        /// Two overloaded contstructors for runway. We can start a runway with one node, or we can just give it a list of nodes.
        /// </summary>
        /// <param name="nodes or node"> </param>

        public Runway()
            : base()
        {
            _heading = -1;
        }

        public Runway(int id, string name, int maxWeight, int length, 
            int width, int elevation, int heading, RunwayStatus currentRunwayStatus)
            : base(id, name, maxWeight, length, width, elevation)
        {
            _heading = heading;
            _currentRunwayStatus = currentRunwayStatus;
        }

        [DataMember]
        public int Heading
        {
            get
            {
                return _heading;
            }

            set
            {
                if (_heading != value)
                {
                    _heading = value;
                }
            }
        }

        [DataMember]
        public RunwayStatus CurrentRunwayStatus
        {
            get
            {
                return _currentRunwayStatus;
            }

            set
            {
                if (_currentRunwayStatus != value)
                {
                    _currentRunwayStatus = value;
                }
            }
        }
        
        [DataMember]
        public String Direction1
        {
            get { return _direction1; }
            set { _direction1 = value; }
        }

        [DataMember]
        public String Direction2
        {
            get { return _direction2; }
            set { _direction2 = value; }
        }

        public void AddNode(Node node)
        {
            Nodes.Add(node);
        }

        public void SetLabelLocation(String nodeString, double scaleX = 1, double scaleY = 1)
        {
            this._labelLocation = this.parseNodeFromString(nodeString, scaleX, scaleY);
        }

        public override String ToString()
        {
            String output = "{ Runway \n" +
                            "\t Direction1: " + this._direction1 + ", Direction2: " + this._direction2 + "\n" +
                            "\t LabelLocation: " + this._labelLocation + "\n" +
                            "\t MaxWeight: " + this.MaxWeight + "\n" +
                            "\t Width: " + this.Width + "\n" +
                            "\t RunwayStatus: " + _currentRunwayStatus + "\n" +
                            "\t Nodes: \n";

            foreach (Node node in this.Nodes)
            {
                output += "\t\t [" + node + "]\n";
            }

            output += "}";

            return output;
        }
    }

    [DataContract]
    public enum RunwayStatus
    {
        [EnumMember]
        ARRIVE,
        [EnumMember]
        DEPART,
        [EnumMember]
        ARRIVE_DEPART
    }
}
